from twisted.internet import reactor
from twisted.web.client import getPage
from twisted.python.util import println

urls=['http://www.baidu.com/',
      'http://zhidao.baidu.com/',
      'http://mp3.baidu.com/',
      'http://tieba.baidu.com/'      
      ]
def get_next_page(*t,**kw):
    while urls:
        get_page(urls.pop())

def print_msg(*msg,**karg):
    print msg,karg
    pass
def handle_err(err):
    print '------------------error-------------------'
    print err
def get_page(url):
    d=getPage(url).addCallbacks(
        callback=print_msg,
        errback=handle_err).addBoth(get_next_page)

    print 'get:'+url
get_next_page()
#print dir(reactor)
class c():
    def f(self):
        try:
            reactor.run()
        except:
            print 'end'
            reactor.stop()

a=c()
a.f()
